package day2;

import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;

public class DoPrivileged {
	void doPrivileged() throws SecurityException, NoSuchMethodException{
		Class<Person> clazz = Person.class;
		final Method method = clazz.getMethod("setPriName");
		method.setAccessible(true);
		
		AccessController.doPrivileged(new PrivilegedAction<Object>() {
			public Object run() {
				method.setAccessible(false);
				return null;
			}
		});
	}
	
}

class Person{
	String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		setPriName();
		this.name = name;
	}
	
	private void setPriName(){
		
	}
}
